package com.yb.guigu.pick.auth.controller;


import com.yb.guigu.pick.auth.bean.vo.request.RouteCreateRequest;
import com.yb.guigu.pick.auth.service.ISysRouteService;
import com.yb.guigu.pick.core.bean.GuiguResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚兵
 * @since 2023-06-04
 */
@RestController
@RequestMapping("/sysroute")
public class SysRouteController {
    @Autowired
    ISysRouteService routeService;

    @GetMapping("/all")
    public GuiguResult routeAllTree()  {
        return routeService.routeAll();
    }


    @GetMapping("/list")
    public GuiguResult routeAll()  {
        return routeService.listAll();
    }


    @GetMapping("/user/list")
    public GuiguResult routeUserAll(){
        return routeService.listForUser();
    }

    @GetMapping("/level/{parentId}")
    public GuiguResult queryLevelList(@PathVariable Integer parentId){
        return routeService.queryLevelList(parentId,false);
    }


    @GetMapping("/level/menu/{parentId}")
    public GuiguResult queryLevelMenuList(@PathVariable Integer parentId){
        return routeService.queryLevelList(parentId,true);
    }


    /**
     * 只查询菜单的路由
     * @return
     */
    @GetMapping("/menus")
    public GuiguResult menus(){
        return routeService.menus();
    }

    @PostMapping("/create")
    public GuiguResult create(@RequestBody @Valid RouteCreateRequest routeCreateRequest){
        return routeService.create(routeCreateRequest);
    }
}
